-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Enhancement/issue 8427 #8811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement/issue 8427 #8811
Conversation
for more information, see https://pre-commit.ci
web_programming/sliding_window.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty file, should be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have modified and filled it in
>>> print(next(sw_gen)) | ||
[1, 2, 3] | ||
>>> print(next(sw_gen)) | ||
[2, 3, 4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test to check whether the generator stops at the correct index when it reaches the end of the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm doesn't fit in web_programming
. I think it'd fit better under other
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification, I have moved the files to other folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we already have an implementation of max subarray sum in maths/kadanes.py
, other/maximum_subarray.py
, maths/largest_subarray_sum.py
, other/maximum_subsequence.py
, and dynamic_programming/max_sum_contiguous_subsequence.py
. Furthermore, dynamic_programming/max_sub_array.py
and divide_and_conquer/max_subarray_sum.py
both implement this algorithm has a subroutine.
... I have no idea why there are so many near-duplicate implementations of the same algorithm, but this really shouldn't be the case. I'll open an issue to address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #8812
Also, some of these commits don't pertain to the algorithm contribution itself (Create/Delete TestShiva, Add black version/delete black file, etc.), so this PR could use a rebase to get those commits deleted/squashed before it's merged |
In the commit body, the box is checked next to
yet there are three algorithm files in this pull request. How is the first file better than Python/maths/largest_subarray_sum.py Line 4 in fa12b9a
Is it more concise or faster? If so, do we have a benchmark to prove that? |
Example: | ||
>>> arr = [-2, -3, 4, -1, -2, 5, -3] | ||
>>> max_sub_array_sum(arr, len(arr)) | ||
6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a blank line to the tests pass.
6 | |
6 | |
As discussed in CONTRIBUTING.md
please test your code by running on your local machine:
% python3 -m doctest -v dynamic_programming/max_sub_array_sum.py
window = elements[i : i + window_size] | ||
windows.append(window) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window = elements[i : i + window_size] | |
windows.append(window) | |
windows.append(elements[i : i + window_size]) |
>>> print(next(sw_gen)) | ||
[1, 2, 3] | ||
>>> print(next(sw_gen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> print(next(sw_gen)) | |
[1, 2, 3] | |
>>> print(next(sw_gen)) | |
>>> next(sw_gen) | |
[1, 2, 3] | |
>>> next(sw_gen) |
Describe your change:
Impelementation of 2 algorithms from the ones mentioned in the issue #8427 , namely the sliding window algorithm and Kadane's algorithm.
Checklist:
Fixes: #{$ISSUE_NO}
.